<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link rel="stylesheet" href="css/style_init.css"> -->
    <style>
        .box {
            float: right;
            border: 1px solid slategrey;
            overflow: hidden;
        }
        .box img {
            transform-origin: center center;
            transition: all .2s;
        }
        .box:hover img {
            transform: scale(2);
        }
        .box2 {
            float: right;
        }
        tr>td {
            padding: 2px 3px;
        }
        tr>td:first-child {
            /* color: aqua; */
            font-weight: 700;
        }
        input[id*=g] {
            color:#066;
            cursor: not-allowed;
        }
        td input {
            border: none;
            outline: none;
        }
        #peoplenum:focus,
        td:nth-child(2) input:focus {
            background-color: rgb(188, 243, 225);
        }
        button {
            cursor: pointer;
        }
    </style>
</head>
<body>
    <!-- <div class="box">
        <img src="../images/png/aichong05.png" alt="">
    </div> -->
    <div class="box2">
        <p>Fi = 75 - |Di - D| / D * 100 * E</p>
        <p>Fi:有效投标人报价得分，本项最高得分为75分；</p>
        <p>Di:有效投标人的评标报价</p>
        <p>Di = 2000000 *（1-有效投标人投标下浮系数）；</p>
        <p>D：评标基准价，有效投标人家数为i；</p>
        <p>0 ＜ i ＜ 6时，评标基准价为所有有效投标人评标价的算术平均值；</p>
        <p>6 ≤ i ＜ 9时，评标基准价为去掉1个最高评标报价和1个最低评标报价后，其他有效投标人评标价的算术平均值；</p>
        <p>i ≥ 9时，评标基准价为去掉2个最高评标报价和2个最低评标报价后，其他有效投标人评标价的算术平均值；</p>
        <p>E值的确定：E ＝ 0.5。</p>
        <p>以上计算结果采用四舍五入法保留2位小数。</p>
    </div>
    <table border="1">
        <tr>
            <th>投标人序号</th>
            <th>投标价格</th>
            <th>投标得分</th>
        <tr>
        <tr>
            <td>投标人1</td>
            <td><input id="0" type="number" value="" autofocus></td>
            <td><input id="g0" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人2</td>
            <td><input id="1" type="number" value=""></td>
            <td><input id="g1" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人3</td>
            <td><input id="2" type="number" value=""></td>
            <td><input id="g2" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人4</td>
            <td><input id="3" type="number" value=""></td>
            <td><input id="g3" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人5</td>
            <td><input id="4" type="number" value=""></td>
            <td><input id="g4" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人6</td>
            <td><input id="5" type="number" value=""></td>
            <td><input id="g5" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人7</td>
            <td><input id="6" type="number" value=""></td>
            <td><input id="g6" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人8</td>
            <td><input id="7" type="number" value=""></td>
            <td><input id="g7" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人9</td>
            <td><input id="8" type="number" value=""></td>
            <td><input id="g8" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人10</td>
            <td><input id="9" type="number" value=""></td>
            <td><input id="g9" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人11</td>
            <td><input id="10" type="number" value=""></td>
            <td><input id="g10" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人12</td>
            <td><input id="11" type="number" value=""></td>
            <td><input id="g11" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人13</td>
            <td><input id="12" type="number" value=""></td>
            <td><input id="g12" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人14</td>
            <td><input id="13" type="number" value=""></td>
            <td><input id="g13" type="number" value="" readOnly="true"></td>
        </tr>
        <tr>
            <td>投标人15</td>
            <td><input id="14" type="number" value=""></td>
            <td><input id="g14" type="number" value="" readOnly="true"></td>
        </tr>
    </table>
    <hr>
    <div>
        <span>投标人数: </span><input id="peoplenum" type="number" value="0">
        <!-- <br>
        <br>
        <button>清空数据</button> -->
        <button onclick="getNum()">开始计算</button>
    </div>
    <br>
    <br>
    <div><span>投标均值D: </span><input id="avg" type="number" value="0" readOnly="true"></div>
    
</body>
<script>
    function getNum () {
        for (let i = 0; i < 15; i++) {
            document.getElementById('g' + i).value = ''
        }
        let num = document.getElementById('peoplenum').value
        if (num <= 0 || num > 15) {
            alert('参数有误!')
            return
        }
        let D = 0
        let sumD = 0
        if (num < 6) {
            for (let i = 0; i < num; i ++) {
                sumD += parseInt(document.getElementById(i + '').value)
            }
            D = sumD / num
        }
        let arrD = []
        for (let i = 0; i < num; i ++) {
            arrD[i] = parseInt(document.getElementById(i + '').value)
        }
        for (let i = 0; i < num; i++) {
            for (let j = 0; j < num - 1 - i; j++) {
                if (arrD[j] > arrD[j + 1]) {        // 相邻元素两两对比
                    let temp = arrD[j + 1];         // 元素交换
                    arrD[j + 1] = arrD[j];
                    arrD[j] = temp;
                }
            }
        }
        if (num >= 6 && num < 9) {
            for (let i = 1; i < num - 1; i ++) {
                sumD += arrD[i]
            }
            D = sumD / (num - 2)
        } else if (num >= 9) {
            for (let i = 2; i < num - 2; i ++) {
                // console.log(arrD[i])
                sumD += arrD[i]
            }
            D = sumD / (num - 4)
        }
        console.log('均值: ' + D)
        document.getElementById('avg').value = D
        for (let i = 0; i < num; i ++) {
            let cha = parseInt(document.getElementById(i + '').value) - D
            cha = cha < 0 ? -cha : cha
            let fi = 75 - cha / D * 100 * 0.5
            document.getElementById('g' + i).value = fi.toFixed(2)
        }
    }
</script>
</html>